use super::stack::Stack;

pub struct IntoIter<T>(Stack<T>);

impl<T> IntoIter<T> {
    pub fn new(stack: Stack<T>) -> IntoIter<T> {
        IntoIter(stack)
    }
}

impl<T: Clone> Iterator for IntoIter<T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        if !self.0.is_empty() {
            self.0.size -= 1;
            self.0.data.pop()
        } else {
            None
        }
    }
}
